package com.sl.hx.shop.ui.home.presenter;

import android.content.Context;

import com.sl.hx.shop.base.BasePresenter;
import com.sl.hx.shop.bean.HotList;
import com.sl.hx.shop.http.ApiFactory;
import com.sl.hx.shop.http.ApiRetrofit;
import com.sl.hx.shop.http.HttpUtil;
import com.sl.hx.shop.http.ProgressSubscribe;
import com.sl.hx.shop.ui.home.contacts.HotListContacts;
import com.trello.rxlifecycle2.android.ActivityEvent;

import java.util.List;

import io.reactivex.Observable;

public class HotListPresenter extends BasePresenter<HotListContacts.view> implements HotListContacts.presenter {

    private Context mContext;


    public HotListPresenter(Context context) {
        this.mContext = context;

    }

    public void getHotList() {
        Observable observable = ApiFactory.getInstance().getHotList(ApiRetrofit.getCacheControl());
        HttpUtil.getInstance().toSubscribe(observable, new ProgressSubscribe<List<HotList>>(mContext) {
            @Override
            protected void _onNext(List<HotList> hotLists) {
                getView().ShowHotLists(hotLists);
            }

            @Override
            protected void _onError(String message) {
            }

        }, true, getView(), ActivityEvent.DESTROY);
    }
}
